package com.bj58.ecdata.calc.dbservice.crontab;

import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.bj58.ecdata.calc.dbservice.dao.ClickDao;


/**
 * 定时任务，定时清理cpc点击明细数据
 * @author zhaoxiang
 */
@Component
public class ClearRedisData implements InitializingBean {
	@Autowired
	private ClickDao clickDao;
	private Logger log = LoggerFactory.getLogger(ClearRedisData.class);

	@Override
	public void afterPropertiesSet() throws Exception {
	}

	//每分钟清一次
	@Scheduled(cron = "30 0/1 * * * ?")
	public void clearData() {
		try {
			Date date = DateUtils.addMinutes(new Date(), -5);
			long endTime = date.getTime();
			long num = clickDao.clearDetailCacheData(endTime);

			log.info("crontab: clear redis details_click success, {} rows affected", num);
		} catch (Exception e) {
			log.error("clear redis details_click error", e);
		}
	}

}
